import datetime,cgi
import sys
import os
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.dist import use_library
from os import environ
from models import *

class ViewTeam(webapp.RequestHandler):
	def get(self):
		allteams=db.GqlQuery("SELECT * FROM teamDetails")
		tmp2=[]
		for team in allteams:
			teams=db.GqlQuery("SELECT * FROM teamDetails WHERE teamid='%s'" %team.teamid)
			tmp1=[]
			for team in teams:
				tmp=[]
				for member in team.teammember:
					mem=member.split(',')
					membername = db.GqlQuery("SELECT username FROM userDetails WHERE userid='%s'" %mem)
					tmp.append(membername)
			tmp1.append(team.teamid)
			tmp1.append(tmp)
			for project in team.projectids:
				proj=project.split(',')
				projectname = db.GqlQuery("SELECT projectname FROM projectDetails WHERE projectid='%s'" %proj)
				tmp1.append(projectname)
			tmp2.append(tmp1)
		path = os.path.join(os.path.dirname(__file__),'viewteam.html')#use template
		self.response.out.write(template.render(path,{"team":tmp2}))#using template

application = webapp.WSGIApplication([('/viewteam', ViewTeam)], debug=True)

def main():
	run_wsgi_app(application)

if __name__ == "__main__":
	main()
